package com.ZengQi.event.dao.impl;

import com.ZengQi.event.dao.FinishDao;
import com.ZengQi.event.entity.Finish;
import com.ZengQi.event.util.SearchUtils;
import com.ZengQi.event.util.UpdateUtils;

import java.util.List;

public class FinishDapImpl implements FinishDao {
    @Override
    public boolean getIsExistFinish(Finish conditionFinish) {
        String sql="select finish_id finishId,topic_name topicName,finisher,finish_status finishStatus from finish where topic_name=?";
        List<Finish> finishes = SearchUtils.searchForList(Finish.class, sql, conditionFinish.getTopicName());
        if(finishes.size()==0){
            return false;
        }
        return true;
    }

    @Override
    public boolean insertFinishTopic(Finish finish) {
        String sql="insert into finish values(null,?,?,?)";
        boolean update = UpdateUtils.update(sql, finish.getTopicName(), finish.getFinisher(), finish.getFinishStatus());


        return update;
    }

    @Override
    public boolean deleteFinishTopic(Finish conditionFinish) {
        String sql="delete from finish where topic_name=? and finisher=? ";
        boolean update = UpdateUtils.update(sql, conditionFinish.getTopicName(), conditionFinish.getFinisher());


        return update;
    }

    @Override
    public boolean updateFinishByFinisher(Finish finish, String oldFinisher) {

        String sql="update finish set finisher=? where finisher=? ";
        boolean update = UpdateUtils.update(sql, finish.getFinisher(), oldFinisher);

        return update;
    }

    @Override
    public List<Finish> getFinishedTopicByUserName(Finish cinditionFinish) {
        String sql="select finish_id finishId,topic_name topicName,finisher,finish_status finishStatus from finish where finisher=?";
        List<Finish> finishes = SearchUtils.searchForList(Finish.class, sql, cinditionFinish.getFinisher());
        return finishes;
    }
}
